import uuid
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware

from src.web.v1.api import router as v1_router

app = FastAPI()

# 添加 CORS 中间件
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 添加请求 ID 中间件
@app.middleware("http")
async def add_request_id(request: Request, call_next):
    request.state.request_id = str(uuid.uuid4())
    response = await call_next(request)
    return response

# 包含 API 路由
app.include_router(v1_router, prefix="/v1") 